
import create from 'zustand';
import { devtools } from 'zustand/middleware';

interface AnalysisTask {
  name: string,
  tailno: string,
  start_time: string,
  end_time: string,

}
export interface AnalysisTaskState {
  analysisTask: AnalysisTask
}

export interface AnalysisTaskAction {
  update: (analysisTask: AnalysisTask) => void;
}

const initState = (): AnalysisTaskState => {
  return {
    analysisTask: {
      name: '',
      tailno: '',
      start_time: '',
      end_time: '',
    },
  };
};

export const useAnalysisTaskStore = create<AnalysisTaskState & AnalysisTaskAction>(
// @ts-ignore
  devtools(
    (set, get, api) => ({
      ...initState(),
      update: (analysisTask: AnalysisTask) => {
        set({ analysisTask });
      },
    }),
  ),
);

export const useAnalysisTask = () => {
  const { analysisTask, update } = useAnalysisTaskStore();
  return {
    analysisTask,
    update,
  };
};
